<#include "include/_meta.html">
<title>帐户列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container" id="app">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" @click="role_add('添加系统角色','/roles/toAddRole','900','500')" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe600;</i> 添加
			</a>
			<a href="javascript:;" @click="deleteAllRoles()" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i> 删除
			</a>
		</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="9">角色列表</th>
            </tr>
            <tr class="text-c">
                <th width="100"><input type="checkbox" name="" id="" value=""></th>
                <th width="100">角色名称</th>
                <th width="100">角色编码</th>
                <th width="50">是否启用</th>
                <th width="100">添加时间</th>
                <th width="300">角色描述</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr class="text-c" v-for="item in result">
                <td>
                    <input type='checkbox' :value="item.roleid" v-model="checks">
                </td>
                <td>{{item.rolename}}</td>
                <td>{{item.roleid}}</td>
                <td>{{item.isabled}}</td>
                <td>{{item.addtime}}</td>
                <td>{{item.decrib}}</td>
                <td>
                    <a title="编辑" href="javascript:;" @click="role_edit('角色编辑','/roles/toRoleEdit',item.roleid,'900','500')" class="ml-5" style="text-decoration:none">
                        <i class="Hui-iconfont">&#xe6df;</i>
                    </a>
                    <a title="删除" href="javascript:;" @click="role_del(item.roleid)" class="ml-5" style="text-decoration:none">
                        <i class="Hui-iconfont">&#xe6e2;</i>
                    </a>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="pagenav" class="pageNav"></div>
</div>

<#include "include/_footer.html">

<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            result: [],
            checks: []
        },
        methods: {
            //删除单个角色
            role_del:function (roleid){
                layer.confirm('确认要删除吗？',function(){
                    $.ajax({
                        type: 'delete',
                        data: "roleid="+roleid,
                        url:'/roles/deleteRole'
                    });
                    layer.msg('已删除!',{icon:1,time:1000});
                    location.replace(location.href);
                });

            },
            //角色编辑
            role_edit:function (title,url,id,w,h){
                layer_show(title,url+"/"+id,w,h);
            },
            //角色添加
            role_add:function (title,url,w,h){
                layer_show(title,url,w,h);
            },
            //删除复选框选中的所有角色
            deleteAllRoles:function (){
                let array = new Array(this.checks);
                if (this.checks.length == 0){
                    layer.msg('请选择需要删除的角色!',{icon:5,time:1000});
                }else {
                    layer.confirm('确认要删除吗？',function(){
                        $.ajax({
                            type: 'delete',
                            data: {
                                id:array
                            },
                            traditional:true,
                            url:'/roles/deleteAllRoles'
                        });
                        layer.msg('已删除!',{icon:1,time:1000});
                        location.replace(location.href);
                    });
                }
            }
        }
    });

    var getPageList = function (curr) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/roles/selectRoles',
            data: {
                pageNo: curr || 1,
                pageSize: 5
            },
            success: function (msg) {
                app.result = msg.list;
                laypage({
                    cont: "pagenav",
                    pages: msg.pages,
                    skin: '#f5fafe',
                    groups: 3,
                    first: "首页",
                    last: "最后一页",
                    curr: curr || 1,
                    jump: function (obj, first) {
                        console.log(first);
                        if (!first) {
                            getPageList(obj.curr);
                        }
                    }
                });
            }
        });
    }
    getPageList();


</script>
</body>
</html>